package com.ruoyi.integral.service.impl;

import com.ruoyi.common.constant.IntegralConstants;
import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.integral.domain.IntegralMenu;
import com.ruoyi.integral.domain.XwIntegral;
import com.ruoyi.integral.mapper.IntegralMenuMapper;
import com.ruoyi.integral.mapper.XwIntegralMapper;
import com.ruoyi.integral.service.IXwIntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行为c积分管理 服务层实现
 * 
 * @author ruoyi
 * @date 2018-10-24
 */
@Service
public class XwIntegralServiceImpl implements IXwIntegralService 
{
	@Autowired
	private XwIntegralMapper xwIntegralMapper;

	@Autowired
	private IntegralMenuMapper integralMenuMapper;
	/**
     * 查询行为c积分管理信息
     * 
     * @param behaviorId 行为c积分管理ID
     * @return 行为c积分管理信息
     */
    @Override
	public XwIntegral selectXwIntegralById(Integer behaviorId)
	{
		XwIntegral xw = xwIntegralMapper.selectXwIntegralById(behaviorId);
		if(xw.getMenuId()!=null){
			IntegralMenu menu = integralMenuMapper.selectIntegralMenuById(Integer.parseInt(xw.getMenuId()));
			if (menu!=null){
				xw.setMenuType(menu.getTypeName());
			}
		}
	    return xw;
	}
	
	/**
     * 查询行为c积分管理列表
     * 
     * @param xwIntegral 行为c积分管理信息
     * @return 行为c积分管理集合
     */
	@Override
	public List<XwIntegral> selectXwIntegralList(XwIntegral xwIntegral)
	{
	    return xwIntegralMapper.selectXwIntegralList(xwIntegral);
	}
	
    /**
     * 新增行为c积分管理
     * 
     * @param xwIntegral 行为c积分管理信息
     * @return 结果
     */
	@Override
	public int insertXwIntegral(XwIntegral xwIntegral)
	{
		xwIntegral.setCreateTime(DateUtils.getNowDate());
		return xwIntegralMapper.insertXwIntegral(xwIntegral);
	}
	
	/**
     * 修改行为c积分管理
     * 
     * @param xwIntegral 行为c积分管理信息
     * @return 结果
     */
	@Override
	public int updateXwIntegral(XwIntegral xwIntegral)
	{
		xwIntegral.setUpdateTime(DateUtils.getNowDate());
		return xwIntegralMapper.updateXwIntegral(xwIntegral);
	}

	/**
     * 删除行为c积分管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteXwIntegralByIds(String ids)
	{
		return xwIntegralMapper.deleteXwIntegralByIds(Convert.toStrArray(ids));
	}

    /**
     * 禁用行为c积分管理
     */
    @Override
    public int integralTyBehaviorId(Integer behaviorId) {
        XwIntegral xw =  xwIntegralMapper.selectXwIntegralById(behaviorId);
        xw.setStatus(IntegralConstants.INTEGRAL_JIN_YONG);
        return  xwIntegralMapper.updateXwIntegral(xw);
    }

}
